package com.huahai.cofig;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * caffeine缓存配置类
 * @author huahai
 */
@Configuration
public class CacheConfig {
    /**
     * 本地缓存构造方法
     * @return 本地缓存
     */
    @Bean
    public Cache<String, String> localCache() {

        return Caffeine.newBuilder()
                .initialCapacity(1024)
                .maximumSize(10000L)
                .expireAfterWrite(5L, TimeUnit.MINUTES)
                .build();
    }
}